<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>输入ASCII</title>
</head>
<body>
<label>
    请输入数字：
    <input type="text" onkeypress="function1()">
</label>
<script type="text/javascript">
    function function1(){
        if (window.event.keyCode<48||window.event.keyCode>57){
            alert("只能输入数字");
            window.event.preventDefault();  // 取消默认操作，即阻止操作
        }
    }
</script>
</body>
</html>